/*
 * Login.h
 *
 *  Created on: Jul 9, 2024
 *      Author: root
 */

#ifndef BSP_SQL_LOGIN_H_
#define BSP_SQL_LOGIN_H_
#include "basic_header.h"
#include "MySql.h"

namespace bsp {

class Login {
public:
	Login();
	virtual ~Login();

	enum class ErrCode : uint8_t {
		OK,
		USERNAME_PWD_IS_NULL,
		PARAMETER_NOT_LEGAL,
		ALREADY_EXIST,
		SQL_QUERY_ERR,
		SQL_NO_DATA,
	};

	typedef struct UserMode {
		UserMode() :
				id { -1 } {

		}

		int id;
		std::string username;
	} UserMode;

	static UserMode getUser(MYSQL *conn, const char *username);
	static UserMode getUser(MYSQL *conn, std::string username) {
		return getUser(conn, username.c_str());
	}

	static bool registerUser(MYSQL *conn, const char *username, const char *pwd,
			ErrCode *err);
	static bool registerUser(MYSQL *conn, std::string username, std::string pwd,
			ErrCode *err) {
		return registerUser(conn, username.c_str(), pwd.c_str(), err);
	}

	static bool login(MYSQL *conn, const char *username, const char *pwd,
			ErrCode *err);
	static bool login(MYSQL *conn, std::string username, std::string pwd,
			ErrCode *err) {
		return login(conn, username.c_str(), pwd.c_str(), err);
	}

	static bool delUser(MYSQL *conn, const char *username, ErrCode *err);
	static bool delUser(MYSQL *conn, std::string username, ErrCode *err) {
		return delUser(conn, username.c_str(), err);
	}

	static void test1();
};
}
/* namespace bsp */

#endif /* BSP_SQL_LOGIN_H_ */
